package com.fqgj.sentry.policy.server;

import com.fqgj.sentry.policy.client.PolicyService;
import com.fqgj.sentry.policy.dao.PcPolicyDao;
import com.fqgj.sentry.policy.domain.policy.Policy;
import com.fqgj.sentry.policy.domain.policy.PolicyUpdate;
import com.fqgj.sentry.policy.entity.PcPolicyEntity;
import com.fqgj.sentry.policy.server.policy.AddPolicyService;
import com.fqgj.sentry.policy.server.policy.PolicyUpdateDeletedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: yujianfu (mr.vencnet@gmail.com)
 * Date: 2017/7/13
 * Time: 下午9:43
 */
@Service
@Transactional
public class PolicyServiceImpl implements PolicyService {

    @Autowired
    private PolicyUpdateDeletedService policyUpdateDeletedService;

    @Autowired
    private PcPolicyDao pcPolicyDao;

    @Autowired
    private AddPolicyService addPolicyService;


    /**
     * 策略的新增
     *
     * @param executorId
     * @param policy
     * @return
     */
    @Override
    public Boolean add(Long executorId, Long policySetsId, Long merchantId, Policy policy) {
        return addPolicyService.execute(executorId, policySetsId, merchantId, policy);
    }

    @Override
    public PcPolicyEntity findById(Long policyId) {
        return pcPolicyDao.selectByPrimaryKey(policyId);
    }

    /**
     * 策略的修改
     *
     * @param policy
     * @return
     */
    @Override
    public Boolean update(Long policyId, PolicyUpdate policy) {
        return policyUpdateDeletedService.update(policyId, policy);
    }

    /**
     * 策略的修改
     *
     * @param sort
     * @return
     */
    @Override
    public Boolean updatePolicySort(Long policyId, Integer sort) {
        return pcPolicyDao.updatePolicySort(policyId, sort);
    }
    /**
     * 策略集 删除
     *
     * @param policyId
     * @return
     */
    @Override
    public Boolean delete(Long merchantId, Long policyId) {
        return policyUpdateDeletedService.delete(merchantId, policyId);
    }

    /**
     * 根据执行者  查询策略集合
     *
     * @param executorId
     * @return
     */
    @Override
    public List<PcPolicyEntity> selectPolicyByExecutorId(Long executorId) {
        return pcPolicyDao.selectPolicyByExecutorId(executorId);
    }

    @Override
    public List<PcPolicyEntity> selectPolicyByPolicySetId(Long policySetId) {
        return pcPolicyDao.selectPolicyByPolicySetId(policySetId);
    }

    @Override
    public List<PcPolicyEntity> selectByPolicySetIdAndExecutorId(Long policySetId, Long executorId) {
        return pcPolicyDao.selectByPolicySetIdAndExecutorId(policySetId, executorId);
    }
}
